package com.peanut.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.peanut.domain.po.TabUser;
import com.peanut.mapper.TabUserMapper;
import com.peanut.service.UserManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserManagerServiceImpl implements UserManagerService {

    @Resource
    private TabUserMapper userMapper;
    @Override
    public List<TabUser> findAllUser(TabUser user) {
        List<TabUser> tabUsers = userMapper.selectList(null);
        return tabUsers;
    }

    @Override
    public List<TabUser> findUser(TabUser user) {
        QueryWrapper<TabUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",user.getUserName());
        List<TabUser> userList = userMapper.selectList(wrapper);
        return userList;
    }

    @Override
    public int updateUser(TabUser user) {
        UpdateWrapper<TabUser> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_name",user.getUserName());
        int i = userMapper.update(user,wrapper);
        return i;
    }

    @Override
    public void deleteUser(TabUser user) {
        QueryWrapper<TabUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",user.getUserName());
        userMapper.delete(wrapper);
    }

    @Override
    public TabUser selectBtPid(Long userId) {
        TabUser user = userMapper.selectById(userId);
        return user;
    }

    @Override
    public TabUser login(String username) {
        return userMapper.selectByName(username);
    }
}
